// 保留4位小数
export function maxDecimal(number) {
  if (!number) {
    return number
  }
  number = String(number).replace(/^(.*\..{4}).*$/, '$1')
  return Number(number)
}
// 保留2位小数
export function maxDecimal2(number) {
  if (!number) {
    return number
  }
  number = String(number).replace(/^(.*\..{2}).*$/, '$1')
  return Number(number)
}
// 金额用，分开 如1,456,456,123.22
export function numFormat(num) {
  const c = (Number(num).toString().indexOf('.') !== -1) ? num.toLocaleString() : Number(num).toString()
    .replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  return c
}
export function mul(arg1, arg2) { // 乘法
  let m = 0
  const s1 = arg1.toString()
  const s2 = arg2.toString()
  try {
    m += s1.split('.')[1].length
  } catch (e) {
    // console.log(e)
  }
  try {
    m += s2.split('.')[1].length
  } catch (e) {
    // console.log(e)
  }
  return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m)
}

